<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="快递单号" prop="deliveryId">
        <el-input v-model="queryParams.deliveryId" placeholder="请输入快递单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单号" align="center" prop="orderId" />
      <el-table-column label="用户姓名" align="center" prop="userName" />
      <el-table-column label="商品id" align="center" prop="goodsId" />
      <el-table-column label="支付状态" align="center" prop="payStatus">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.payStatus==1">已支付</el-tag>
          <el-tag type="danger" v-else>未支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.status== -3">退款成功</el-tag>
          <el-tag type="danger" v-if="scope.row.status== -2">申请退货</el-tag>
          <el-tag type="danger" v-if="scope.row.status== -1">退货成功</el-tag>
          <el-tag type="primary" v-if="scope.row.status== 0">待发货</el-tag>
          <el-tag type="primary" v-if="scope.row.status== 1">待收货</el-tag>
          <el-tag type="primary" v-if="scope.row.status== 2">已收货</el-tag>
          <el-tag type="success" v-if="scope.row.status== 3">已完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['order:order:edit']">订单详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['order:order:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 添加或修改订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <div style="margin:20px">
        <el-steps :space="200" :active="1" finish-status="success">
          <el-step title="用户下单"></el-step>
          <el-step title="待发货"></el-step>
          <el-step title="待收货"></el-step>
          <el-step title="待评价"></el-step>
          <el-step title="已完成"></el-step>
        </el-steps>
      </div>
      <div style="margin:20px">
        <div><span>当前订单状态：</span></div>
        <div style="text-align:right">
          <el-button type="info">去发货</el-button>
          <el-button type="info">订单备注</el-button>
        </div>
      </div>
      <span>基本信息</span>
      <el-table :data="orderX" border style="width: 100%">
        <!-- 基本信息 -->
        <el-table-column prop="orderId" label="订单号" width="180">
        </el-table-column>
        <el-table-column prop="userName" label="用户姓名" width="180">
        </el-table-column>
        <el-table-column prop="payType" label="支付方式" width="180">
        </el-table-column>
      </el-table>
      <el-divider></el-divider>
      <span>收货人信息</span>
      <!-- 收货人信息 -->
      <el-table :data="orderX" border style="width: 100%">
        <el-table-column prop="userName" label="用户姓名" width="180">
        </el-table-column>
        <el-table-column prop="userPhone" label="手机号码" width="180">
        </el-table-column>
        <el-table-column prop="userAddress" label="收货地址" width="180">
        </el-table-column>
        <el-table-column prop="isDel" label="备注" width="180">
        </el-table-column>
      </el-table>
      <!-- 商品信息 -->
      <el-divider></el-divider>
      <span>商品信息</span>
      <el-table :data="orderX" border style="width: 100%">
        <el-table-column prop="userAddress" label="收货地址" width="180">
        </el-table-column>
        <el-table-column prop="userName" label="用户姓名" width="180">
        </el-table-column>
      </el-table>
      <!-- 费用信息 -->
      <el-divider></el-divider>
      <span>费用信息</span>
      <el-table :data="orderX" border style="width: 100%">
        <el-table-column prop="userAddress" label="收货地址" width="180">
        </el-table-column>
        <el-table-column prop="userName" label="用户姓名" width="180">
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/order/order";

export default {
  name: "Order",
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单信息表格数据
      orderList: [],
      orderX: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        goodsId: null,
        userId: null,
        userName: null,
        userAddress: null,
        cartId: null,
        totalPrice: null,
        payPrice: null,
        payStatus: null,
        payTime: null,
        payType: null,
        status: null,
        refundStatus: null,
        totalNum: null,
        deliverySn: null,
        deliveryId: null,
        useIntegral: null,
        mark: null,
        isDel: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询订单信息列表 */
    getList () {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        console.log(this.orderList)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        orderId: null,
        goodsId: null,
        userId: null,
        userName: null,
        userAddress: null,
        cartId: null,
        totalPrice: null,
        payPrice: null,
        payStatus: 0,
        payTime: null,
        payType: null,
        status: 0,
        refundStatus: 0,
        totalNum: null,
        deliverySn: null,
        deliveryId: null,
        useIntegral: null,
        mark: null,
        isDel: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.title = "添加订单信息";
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const id = row.id || this.ids
      this.orderX = []
      getOrder(id).then(response => {
        this.form = response.data;
        this.orderX.push(response.data)
        console.log(this.orderX)
        this.open = true;
        this.title = "查看订单详情";
      });
    },
    /** 提交按钮 */
    submitForm () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单信息编号为"' + ids + '"的数据项？').then(function () {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download('order/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
